home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 5 / Amiga Tools 5.iso / grafik / 3d & render tools / irit / contrib / dat2sen / dat2sen.c < prev   
Encoding:
C/C++ Source or Header  |  1996-07-16  |  7.2 KB  |  196 lines

  1. /*****************************************************************************
  2. * Filter to convert IRIT data files to SENAC .sdat files.                    *
  3. * Based on dat2irit                                                      *
  4. *   Written by:  Gershon Elber                Ver 1.0, Sep 1991    *
  5. *                                                                            *
  6. * Written by: M Glanvill 1995, contact senac@waikato.ac.nz                   *
  7. *****************************************************************************/
  8.  
  9. #include <stdio.h>
  10. #include <math.h>
  11. #include <string.h>
  12. #include "irit_sm.h"
  13. #include "iritprsr.h"
  14. #include "allocate.h"
  15. #include "attribut.h"
  16. #include "cagd_lib.h"
  17. #include "symb_lib.h"
  18. #include "triv_lib.h"
  19. #include "trim_lib.h"
  20. #include "getarg.h"
  21. #include "genmat.h"
  22.  
  23. #ifdef NO_CONCAT_STR
  24. static char *VersionStr =
  25.     "Dat2Sen        Version 1.2,    Martin Glanvill    ,\n\
  26.      (C) Copyright 1995/6 M Glanvill, U.O.W..";
  27. #else
  28. static char *VersionStr = "Dat2sen    " VERSION ",    Gershon Elber/M. Glanvill,     "
  29.     __DATE__ ",   " __TIME__ "\n" COPYRIGHT ", Non commercial use only.";
  30. #endif /* NO_CONCAT_STR */
  31.  
  32. static char
  33.     *CtrlStr = "dat2sen z%- DFiles!*s";
  34.  
  35. static void DumpDataForIrit(IPObjectStruct *PObjects);
  36. static void DumpOneObject(FILE *f, IPObjectStruct *PObject, int Level);
  37. static void DumpOnePolygon(FILE *f,
  38.                IPPolygonStruct *PPolygon,
  39.                int PolyNum,
  40.                int IsPolyline);
  41.  
  42. /*****************************************************************************
  43. * DESCRIPTION:                                                               M
  44. * Main module of dat2sen - Read command line and do what is needed...         M
  45. *                                                                            *
  46. * PARAMETERS:                                                                M
  47. *   argc, argv:  Command line.                                               M
  48. *                                                                            *
  49. * RETURN VALUE:                                                              M
  50. *   void                                                                     M
  51. *                                                                            *
  52. * KEYWORDS:                                                                  M
  53. *   main                                                                     M
  54. *****************************************************************************/
  55. void main(int argc, char **argv)
  56. {
  57.     int Error,
  58.     VerFlag = FALSE,
  59.     NumFiles = 0;
  60.     char
  61.     **FileNames = NULL;
  62.     IPObjectStruct *PObjects;
  63.  
  64.     if ((Error = GAGetArgs(argc, argv, CtrlStr,
  65.                &VerFlag, &NumFiles, &FileNames)) != 0) {
  66.     GAPrintErrMsg(Error);
  67.     GAPrintHowTo(CtrlStr);
  68.     exit(1);
  69.     }
  70.  
  71.     if (VerFlag) {
  72.     fprintf(stderr, "\n%s\n\n", VersionStr);
  73.     GAPrintHowTo(CtrlStr);
  74.     exit(0);
  75.     }
  76.  
  77.     if (!NumFiles) {
  78.     fprintf(stderr, "No data file names were given, exit.\n");
  79.     GAPrintHowTo(CtrlStr);
  80.     exit(1);
  81.     }
  82.  
  83.     /* Get the data files: */
  84.     IritPrsrSetFlattenObjects(FALSE);
  85.     if ((PObjects = IritPrsrGetDataFiles(FileNames, NumFiles, TRUE, FALSE)) ==
  86.                                     NULL)
  87.     exit(0);
  88.  
  89.     DumpDataForIrit(PObjects);
  90.  
  91.     exit(0);
  92. }
  93.  
  94. /*****************************************************************************
  95. * DESCRIPTION:                                                               *
  96. * Dumps the given Objects to stdout.                                         *
  97. *                                                                            *
  98. * PARAMETERS:                                                                *
  99. *   PObject:    Objects todump                                               *
  100. *                                                                            *
  101. * RETURN VALUE:                                                              *
  102. *   void                                                                     *
  103. *****************************************************************************/
  104. static void DumpDataForIrit(IPObjectStruct *PObjects)
  105. {
  106.     int NameCount = 1;
  107.     IPObjectStruct
  108.     *PObjHead = PObjects;
  109.  
  110.     for (PObjects = PObjHead; PObjects != NULL; PObjects = PObjects -> Pnext)
  111.     DumpOneObject(stdout, PObjects,1);
  112.  
  113. }
  114.  
  115. /*****************************************************************************
  116. * DESCRIPTION:                                                               *
  117. * Dumps one object PObject to files.                                         *
  118. *                                                                            *
  119. * PARAMETERS:                                                                *
  120. *   f:            File to dump object to.                                    *
  121. *   PObject:      Object to dump to file f.                                  *
  122. *                                                                            *
  123. * RETURN VALUE:                                                              *
  124. *   void                                                                     *
  125. *****************************************************************************/
  126. static void DumpOneObject(FILE *f, IPObjectStruct *PObject, int Level)
  127. {
  128.     static int
  129.     NameCount = 1;
  130.     int i, j;
  131.     char Name[LINE_LEN_LONG];
  132.     IPPolygonStruct *Pl;
  133.     IPObjectStruct *PTmp;
  134.  
  135.     if (PObject -> Name == NULL || strlen(PObject -> Name) == 0)
  136.     sprintf(Name, "NoName%d", NameCount++);
  137.     else
  138.     strcpy(Name, PObject -> Name);
  139.  
  140.     switch (PObject -> ObjType) {
  141.     case IP_OBJ_LIST_OBJ:
  142.         for (i = 0; (PTmp = ListObjectGet(PObject, i)) != NULL; i++)
  143.         DumpOneObject(f, PTmp, Level + 1);
  144.  
  145.         break;
  146.     case IP_OBJ_POLY:
  147.         for (Pl = PObject -> U.Pl, i = 1;
  148.          Pl != NULL; 
  149.          Pl = Pl -> Pnext, i++)
  150.           DumpOnePolygon(f, Pl, i, IP_IS_POLYLINE_OBJ(PObject));
  151.         
  152.             fprintf(f, "EnterPoly %s\n", Name);
  153.         break;
  154.     default:
  155.         fprintf(stderr,"Error: non-polygonal object - use irit2nff\n");
  156.         exit(1);
  157.         break;
  158.  
  159.     }
  160. }
  161.  
  162. /*****************************************************************************
  163. * DESCRIPTION:                                                               *
  164. * Dumps one polygon.                                                         *
  165. *                                                                            *
  166. * PARAMETERS:                                                                *
  167. *   f:          File to dump polygon to.                              *
  168. *   PPolygon:     Polygon to dump to file f.                                 *
  169. *   PolyNum:      Number of polygon.                                         *
  170. *   IsPolyline:   Is it a polyline or a polygon?                             *
  171. *                                                                            *
  172. * RETURN VALUE:                                                              *
  173. *   void                                                             *
  174. *****************************************************************************/
  175. static void DumpOnePolygon(FILE *f,
  176.                IPPolygonStruct *PPolygon,
  177.                int PolyNum,
  178.                int IsPolyline)
  179. {
  180.     int i,
  181.     VCount = 1;
  182.     IPVertexStruct
  183.     *V = PPolygon -> PVertex,
  184.     *VFirst = V;
  185.  
  186.     fprintf(f,"{\n");
  187.     do {
  188.     fprintf(f, "%14.7lg %14.7lg %14.7lg\n", V -> Coord[0], V -> Coord[1], 
  189.         V -> Coord[2], VCount++);
  190.     V = V -> Pnext;
  191.     }
  192.     while (V != VFirst && V != NULL);
  193.     fprintf(f, "} #polyline %s\n", IsPolyline ? "true" : "false" );
  194. }
  195.  
  196.